from fasc_api.client.seal_client import SealClient
from fasc_api.client.service_client import ServiceClient
from fasc_api.exception.exceptions import ClientException
from fasc_api.exception.exceptions import ServerException

from init_demo_data import InitDemoData

api_client = InitDemoData.api_client
access_token = ServiceClient.get_access_token_value(api_client)
print(access_token)
api_client.set_access_token(access_token)


# 查询印章列表
def get_seal_list_demo():
    try:
        data = {
            "openCorpId": "d24c25be1f86474e8d9b661b6976a649",
            "listFilter": {
                "categoryType": [
                    "official_seal"
                ]
            },
            "accessToken": "ed6aaa63d7b147a393ef0a95cf7d476b"
        }
        res = SealClient.get_seal_list(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())


# 查询印章详情
def get_seal_detail_demo():
    try:
        data = {
            "openCorpId": "d24c25be1f86474e8d9b661b6976a649",
            "sealId": 19800,
            "accessToken": "ed6aaa63d7b147a393ef0a95cf7d476b"
        }
        res = SealClient.get_seal_detail(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())


# 获取指定印章详情链接
def get_appointed_seal_url_demo():
    try:
        data = {
            "openCorpId": "d24c25be1f86474e8d9b661b6976a649",
            "sealId": 184386,
            "clientUserId": "AutoClientUserId1656985245",
            "redirectUrl": "http://www.baidu.com",
            "accessToken": "ed6aaa63d7b147a393ef0a95cf7d476b"
        }
        res = SealClient.get_appointed_seal_url(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())


# 查询企业用印员列表
def get_seal_user_list_demo():
    try:
        data = {
            "openCorpId": "d24c25be1f86474e8d9b661b6976a649",
            "listFilter": {
                "categoryType": [
                    "official_seal"
                ]
            },
            "accessToken": "ed6aaa63d7b147a393ef0a95cf7d476b"
        }
        res = SealClient.get_seal_user_list(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())


# 查询指定成员的印章列表
def get_user_seal_list_demo():
    try:
        data = {
            "openCorpId": "d24c25be1f86474e8d9b661b6976a649",
            "memberId": 1980,
            "accessToken": "ed6aaa63d7b147a393ef0a95cf7d476b"
        }
        res = SealClient.get_user_seal_list(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())


# 获取印章创建链接
def get_seal_create_url_demo():
    try:
        data = {
            "openCorpId": "d24c25be1f86474e8d9b661b6976a649",
            "clientUserId": "AutoClientUserId1656985245",
            "sealName": "法人章",
            "categoryType": "official_seal",
            "sealTag": "合同使用",
            "createSerialNo": "191115",
            "redirectUrl": "http://www.baidu.com",
            "accessToken": "ed6aaa63d7b147a393ef0a95cf7d476b"
        }
        res = SealClient.get_seal_create_url(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())


# 查询审核中的印章列表
def get_seal_verify_list_demo():
    try:
        data = {
            "openCorpId": "d24c25be1f86474e8d9b661b6976a649",
            "accessToken": "ed6aaa63d7b147a393ef0a95cf7d476b",
        }
        res = SealClient.get_seal_verify_list(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())


# 修改印章基本信息
def modify_seal_demo():
    try:
        data = {
            "openCorpId": "d24c25be1f86474e8d9b661b6976a649",
            "sealId": 34220,
            "sealName": "法人章",
            "categoryType": "official_seal",
            "sealTag": "测试",
            "accessToken": "ed6aaa63d7b147a393ef0a95cf7d476b"
        }
        res = SealClient.modify_seal(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())


# 获取设置用印员链接
def get_seal_grant_url_demo():
    try:
        data = {
            "openCorpId": "d24c25be1f86474e8d9b661b6976a649",
            "sealId": 34220,
            "memberInfo": {
                "memberIds": [
                    0
                ],
                "grantStartTime": "1677115605000",
                "grantEndTime": "1677215605000"
            },
            "clientUserId": "AutoClientUserId1656985245",
            "redirectUrl": "http://www.baidu.com",
            "accessToken": "ed6aaa63d7b147a393ef0a95cf7d476b"
        }
        res = SealClient.get_seal_grant_url(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())


# 获取设置企业印章免验证签链接
def get_seal_free_sign_url_demo():
    try:
        data = {
            "openCorpId": "d24c25be1f86474e8d9b661b6976a649",
            "clientUserId": "AutoClientUserId1656985245",
            "sealId": 34220,
            "businessId": "342",
            "email": "1677116109675@fdd.com",
            "expiresTime": "1677115605000",
            "redirectUrl": "http://www.baidu.com",
            "accessToken": "ed6aaa63d7b147a393ef0a95cf7d476b"
        }
        res = SealClient.get_seal_free_sign_url(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())


# 解除印章授权
def cancel_seal_grant_demo():
    try:
        data = {
            "openCorpId": "d24c25be1f86474e8d9b661b6976a649",
            "sealId": 184386,
            "memberId": "1656985245",
            "accessToken": "ed6aaa63d7b147a393ef0a95cf7d476b"
        }
        res = SealClient.cancel_seal_grant(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())


# 设置印章状态
def set_seal_status_demo():
    try:
        data = {
            "openCorpId": "d24c25be1f86474e8d9b661b6976a649",
            "sealId": 34220,
            "sealStatus": "enable",
            "accessToken": "ed6aaa63d7b147a393ef0a95cf7d476b"
        }
        res = SealClient.set_seal_status(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())


# 删除印章
def delete_seal_demo():
    try:
        data = {
            "openCorpId": "d24c25be1f86474e8d9b661b6976a649",
            "sealId": 34220,
            "accessToken": "ed6aaa63d7b147a393ef0a95cf7d476b"
        }
        res = SealClient.delete_seal(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())


# 获取印章管理链接
def get_seal_manage_url_demo():
    try:
        data = {
            "openCorpId": "d24c25be1f86474e8d9b661b6976a649",
            "clientUserId": "AutoClientUserId1656985245",
            "redirectUrl": "http://www.baidu.com",
            "accessToken": "ed6aaa63d7b147a393ef0a95cf7d476b"
        }
        res = SealClient.get_seal_manage_url(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())


# 查询个人签名列表
def get_personal_seal_list_demo():
    try:
        data = {
            "openUserId": "745c3bbcaddc46abbf01cd61e28d7aee",
            "accessToken": "ed6aaa63d7b147a393ef0a95cf7d476b"
        }
        res = SealClient.get_personal_seal_list(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())


# 获取设置个人签名免验证签链接
def get_personal_seal_free_sign_url_demo():
    try:
        data = {
            "openUserId": "745c3bbcaddc46abbf01cd61e28d7aee",
            "sealId": 34220,
            "businessId": "234",
            "email": "1677116109675@fdd.com",
            "expiresTime": "1677115605000",
            "redirectUrl": "http://www.baidu.com",
            "accessToken": "ed6aaa63d7b147a393ef0a95cf7d476b"
        }
        res = SealClient.get_personal_seal_free_sign_url(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())


if __name__ == '__main__':
    # 查询印章列表
    get_seal_list_demo()
    # 查询印章详情
    get_seal_detail_demo()
    # 获取指定印章详情链接
    get_appointed_seal_url_demo()
    # 查询企业用印员列表
    get_seal_user_list_demo()
    # 查询指定成员的印章列表
    get_user_seal_list_demo()
    # 获取印章创建链接
    get_seal_create_url_demo()
    # 查询审核中的印章列表
    get_seal_verify_list_demo()
    # 修改印章基本信息
    modify_seal_demo()
    # 获取设置用印员链接
    get_seal_grant_url_demo()
    # 获取设置企业印章免验证签链接
    get_seal_free_sign_url_demo()
    # 解除印章授权
    cancel_seal_grant_demo()
    # 设置印章状态
    set_seal_status_demo()
    # 删除印章
    delete_seal_demo()
    # 获取印章管理链接
    get_seal_manage_url_demo()
    # 查询个人签名列表
    get_personal_seal_list_demo()
    # 获取设置个人签名免验证签链接
    get_personal_seal_free_sign_url_demo()
